<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>portchannel.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
       <span class="fn">portchannel.js</span>
</div>

<div class="g-section g-tpl-75-25">
  <div class="g-unit g-first" id="description">
    A class that wraps several types of HTML5 message-passing
 entities (MessagePorts, WebWorkers, and Windows),
 providing a unified interface.

 This is tested under Chrome, Safari, and Firefox. Since Firefox 3.6 has an
 incomplete implementation of web workers, it doesn&amp;#39;t support sending ports
 over Window connections. IE has no web worker support at all, and so is
 unsupported by this class.
  </div>
  

        <div class="g-unit" id="useful-links">
          <div class="title">Useful links</div>
          <ol>
            <li><a href="closure_goog_messaging_portchannel.js.source.html"><span class='source-code-link'>Source Code</span></a></li>
            <li><a href="http://code.google.com/p/closure-library/source/browse/closure/goog/messaging/portchannel.js">Git</a></li>
          </ol>
        </div>
</div>

<h2 class="g-first">File Location</h2>
  <div class="g-section g-tpl-20-80">
    <div class="g-unit g-first">
      <div class="g-c-cell code-label">messaging/portchannel.js</div>
    </div>
  </div>
<hr/>


  <h2>Classes</h2>
 <div class="fn-constructor">
        <a href="class_goog_messaging_PortChannel.html">
          goog.messaging.PortChannel</a><br/>
        <div class="class-details">A wrapper for several types of HTML5 message-passing entities
(MessagePorts and WebWorkers). This class implements the
goog.messaging.MessageChannel interface.

This class can be used in conjunction with other communication on the port.
It sets goog.messaging.PortChannel.FLAG to true on all messages it
sends.</div>
 </div>
      
<br/>

  <div class="legend">
        <span class="key publickey"></span><span>Public</span>
        <span class="key protectedkey"></span><span>Protected</span>
        <span class="key privatekey"></span><span>Private</span>
  </div>









<div class="section">
  <table class="horiz-rule">


  </table>
</div>




  <h2>Global Functions</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.messaging.PortChannel.forEmbeddedWindow"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.messaging.PortChannel.</span><span class="entryName">forEmbeddedWindow<span class="args">(<span class="arg">window</span>,&nbsp;<span class="arg">peerOrigin</span>,&nbsp;<span class="arg">opt_timer</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="class_goog_messaging_DeferredChannel.html">goog.messaging.DeferredChannel</a></span></div>
      </div>


     <div class="entryOverview">
       Create a PortChannel that communicates with a window embedded in the current
page (e.g. an iframe contentWindow). The code within the window should call
forGlobalWindow to establish the connection.

It&amp;#39;s possible to use this channel in conjunction with other messages to the
embedded window. However, only one PortChannel should be used for a given
window at a time.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">window</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/DOM/window">Window</a></span></div>
        <div class="entryOverview">The window object to communicate with.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">peerOrigin</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">The expected origin of the window. See <a href="http://dev.w3.org/html5/postmsg/#dom-window-postmessage">http://dev.w3.org/html5/postmsg/#dom-window-postmessage</a>.</div>
     </td>
   </tr>
     
   <tr class="even">
     <td>
        <span class="entryName">opt_timer</span>
        : <div class="fullType">(<span class="type"><a href="class_goog_Timer.html">goog.Timer</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span><span>&nbsp;|&nbsp;</span><span class="type">undefined</span>)</div>
        <div class="entryOverview">The timer that regulates how often the initial connection message is attempted. This will be automatically disposed once the connection is established, or when the connection is cancelled.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="class_goog_messaging_DeferredChannel.html">goog.messaging.DeferredChannel</a></span></div>&nbsp;
            The PortChannel. Although this is not actually an instance of the PortChannel class, it will behave like one in that MessagePorts may be sent across it. The DeferredChannel may be cancelled before a connection is established in order to abort the attempt to make a connection.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_messaging_portchannel.js.source.html#line105">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>






  <td>
    <a name="goog.messaging.PortChannel.forGlobalWindow"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.messaging.PortChannel.</span><span class="entryName">forGlobalWindow<span class="args">(<span class="arg">peerOrigin</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="interface_goog_messaging_MessageChannel.html">goog.messaging.MessageChannel</a></span></div>
      </div>


     <div class="entryOverview">
       Create a PortChannel that communicates with the document in which this window
is embedded (e.g. within an iframe). The enclosing document should call
forEmbeddedWindow to establish the connection.

It&amp;#39;s possible to use this channel in conjunction with other messages posted
to the global window. However, only one PortChannel should be used for the
global window at a time.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">peerOrigin</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">The expected origin of the enclosing document. See <a href="http://dev.w3.org/html5/postmsg/#dom-window-postmessage">http://dev.w3.org/html5/postmsg/#dom-window-postmessage</a>.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="interface_goog_messaging_MessageChannel.html">goog.messaging.MessageChannel</a></span></div>&nbsp;
            The PortChannel. Although this may not actually be an instance of the PortChannel class, it will behave like one in that MessagePorts may be sent across it.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_messaging_portchannel.js.source.html#line164">code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



  <h2>Global Properties</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry public">
       <td class="access"></td>





  <a name="goog.messaging.PortChannel.FLAG"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.messaging.PortChannel.</span><span class="entryName">FLAG</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
     </div>


     <div class="entryOverview">
       The flag added to messages that are sent by a PortChannel, and are meant to
be handled by one on the other side.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_messaging_portchannel.js.source.html#line198">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>





  <a name="goog.messaging.PortChannel.REQUIRES_SERIALIZATION_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.messaging.PortChannel.</span><span class="entryName">REQUIRES_SERIALIZATION_</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span></div>
     </div>


     <div class="entryOverview">
       Whether the messages sent across the channel must be JSON-serialized. This is
required for older versions of Webkit, which can only send string messages.

Although Safari and Chrome have separate implementations of message passing,
both of them support passing objects by Webkit 533.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_messaging_portchannel.js.source.html#line211">Code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Directory messaging</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">File Reference</h2>
            <div id="sideFileIndex" rootPath="" current="messaging/portchannel.js"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
